home *** CD-ROM | disk | FTP | other *** search
/ Amiga Tools 2 / Amiga Tools 2.iso / mui / mui-tools / multiuser / src / support / setdefprotect.c < prev    next >
C/C++ Source or Header  |  1995-03-09  |  4KB  |  174 lines

  1. /************************************************************
  2. * MultiUser - MultiUser Task/File Support System                *
  3. * ---------------------------------------------------------    *
  4. * Set the Default Protection Bits                                    *
  5. * ---------------------------------------------------------    *
  6. * © Copyright 1993-1994 Geert Uytterhoeven                        *
  7. * All Rights Reserved.                                                    *
  8. ************************************************************/
  9.  
  10.  
  11. #include <exec/types.h>
  12. #include <dos/dos.h>
  13. #include <proto/exec.h>
  14. #include <proto/dos.h>
  15. #include <utility/tagitem.h>
  16. #include <libraries/multiuser.h>
  17. #include <proto/multiuser.h>
  18.  
  19. #include "SetDefProtect_rev.h"
  20.  
  21. #include "Locale.h"
  22.  
  23. char __VersTag__[] = VERSTAG;
  24.  
  25.  
  26. #define FLAGS_OWNER    1
  27. #define FLAGS_GROUP    2
  28. #define FLAGS_OTHER    3
  29.  
  30.  
  31. static BOOL __regargs ProcessFlags(char *str, ULONG *flags, ULONG type,
  32.                                               struct DosLibrary *DOSBase,
  33.                                               struct ExecBase *SysBase);
  34.  
  35. int __saveds Start(char *arg)
  36. {
  37.     struct ExecBase *SysBase;
  38.     struct DosLibrary *DOSBase;
  39.     struct muBase *muBase = NULL;
  40.     struct RDArgs *args;
  41.     LONG argarray[] = {
  42.         NULL, NULL, NULL, NULL
  43.     };
  44.     ULONG flags = NULL;
  45.     int rc = RETURN_ERROR;
  46.     struct TagItem tags[3];
  47.  
  48.     SysBase = *(struct ExecBase **)4;
  49.  
  50.     if ((!(DOSBase = (struct DosLibrary *)OpenLibrary("dos.library", 37))) ||
  51.          (!(muBase = (struct muBase *)OpenLibrary("multiuser.library", 39)))) {
  52.         rc = ERROR_INVALID_RESIDENT_LIBRARY;
  53.         goto Exit;
  54.     }
  55.  
  56.     args = ReadArgs("FLAGS,GROUP/K,OTHER/K,GLOBAL/S", argarray, NULL);
  57.     if (!args)
  58.         PrintFault(IoErr(), NULL);
  59.     else if (!((argarray[0] && !ProcessFlags((char *)argarray[0], &flags,
  60.                                                           FLAGS_OWNER, DOSBase, SysBase)) ||
  61.                   (argarray[1] && !ProcessFlags((char *)argarray[1], &flags,
  62.                                                           FLAGS_GROUP, DOSBase, SysBase)) ||
  63.                   (argarray[2] && !ProcessFlags((char *)argarray[2], &flags,
  64.                                                           FLAGS_OTHER, DOSBase, SysBase)))) {
  65.         flags ^= FIBF_READ|FIBF_WRITE|FIBF_EXECUTE|FIBF_DELETE;
  66.         tags[0].ti_Tag = muT_DefProtection;
  67.         tags[0].ti_Data = (LONG)flags;
  68.         tags[1].ti_Tag = muT_Global;
  69.         tags[1].ti_Data = (BOOL)argarray[3];
  70.         tags[2].ti_Tag = TAG_DONE;
  71.         if (muSetDefProtectionA(tags))
  72.             rc = RETURN_OK;
  73.         else
  74.             PutStr(GetLocStr(MSG_SETDEFPROTECTFAIL));
  75.     }
  76.     FreeArgs(args);
  77.  
  78. Exit:
  79.     CloseLibrary((struct Library *)muBase);
  80.     CloseLibrary((struct Library *)DOSBase);
  81.  
  82.     return(rc);
  83. }
  84.  
  85.  
  86. static BOOL __regargs ProcessFlags(char *str, ULONG *flags, ULONG type,
  87.                                               struct DosLibrary *DOSBase,
  88.                                               struct ExecBase *SysBase)
  89. {
  90.     int i;
  91.     BOOL rc = TRUE;
  92.  
  93.     for (i = 0; str[i] && rc; i++) {
  94.         switch(str[i]) {
  95.             case 's':
  96.             case 'S':
  97.                 if (type == FLAGS_OWNER)
  98.                     *flags |= FIBF_SCRIPT;
  99.                 else
  100.                     goto Error;
  101.                 break;
  102.  
  103.             case 'p':
  104.             case 'P':
  105.                 if (type == FLAGS_OWNER)
  106.                     *flags |= FIBF_PURE;
  107.                 else
  108.                     goto Error;
  109.                 break;
  110.  
  111.             case 'a':
  112.             case 'A':
  113.                 if (type == FLAGS_OWNER)
  114.                     *flags |= FIBF_ARCHIVE;
  115.                 else
  116.                     goto Error;
  117.                 break;
  118.  
  119.             case 'r':
  120.             case 'R':
  121.                 if (type == FLAGS_OWNER)
  122.                     *flags |= FIBF_READ;
  123.                 else if (type == FLAGS_GROUP)
  124.                     *flags |= FIBF_GRP_READ;
  125.                 else
  126.                     *flags |= FIBF_OTR_READ;
  127.                 break;
  128.  
  129.             case 'w':
  130.             case 'W':
  131.                 if (type == FLAGS_OWNER)
  132.                     *flags |= FIBF_WRITE;
  133.                 else if (type == FLAGS_GROUP)
  134.                     *flags |= FIBF_GRP_WRITE;
  135.                 else
  136.                     *flags |= FIBF_OTR_WRITE;
  137.                 break;
  138.  
  139.             case 'e':
  140.             case 'E':
  141.                 if (type == FLAGS_OWNER)
  142.                     *flags |= FIBF_EXECUTE;
  143.                 else if (type == FLAGS_GROUP)
  144.                     *flags |= FIBF_GRP_EXECUTE;
  145.                 else
  146.                     *flags |= FIBF_OTR_EXECUTE;
  147.                 break;
  148.  
  149.             case 'd':
  150.             case 'D':
  151.                 if (type == FLAGS_OWNER)
  152.                     *flags |= FIBF_DELETE;
  153.                 else if (type == FLAGS_GROUP)
  154.                     *flags |= FIBF_GRP_DELETE;
  155.                 else
  156.                     *flags |= FIBF_OTR_DELETE;
  157.                 break;
  158.  
  159.             default:
  160.             Error:
  161.                 rc = FALSE;
  162.                 PutStr(GetLocStr(MSG_INVALID_FLAG));
  163.                 PutStr(" ");
  164.                 if (type == FLAGS_OWNER)
  165.                     PutStr("SPARWED\n");
  166.                 else
  167.                     PutStr("RWED\n");
  168.                 break;
  169.         }
  170.     }
  171.  
  172.     return(rc);
  173. }
  174.